package org.foundation.jala.jamerzip.modelzip;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import org.foundation.jala.jamerzip.components.JamerElement;
import org.foundation.jala.jamerzip.components.JamerFile;


public class ZipTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private ArrayList<String> fields;
	private List<JamerElement> headerList;
	

	/**
	 * Default constructor
	 */
	public ZipTableModel() {
		this.fields = createDefaultTypeColums();
		this.headerList = new ArrayList<JamerElement>();
	}

	public ArrayList<String> getFields() {
		return fields;
	}

	public synchronized void addHeader(JamerElement newElement) {
		if(newElement==null)
			throw new IllegalArgumentException("ELement ");
		this.headerList.add(newElement);
		fireTableDataChanged();
	}


	@Override
	public int getColumnCount() {
		return this.fields.size();
	}

	@Override
	public int getRowCount() {
		return this.headerList.size();
	}

	@Override
	public String getColumnName(int column) {
		return this.fields.get(column).toString();
	}

	@Override
	public Object getValueAt(int row, int colum) {
		JamerElement currentFile = this.headerList.get(row);
		switch (colum) {
		case 0:
				return currentFile.getName();
		case 1:
			return currentFile.getLastModificationDate();
		case 2:
			return currentFile.getLastModificationTime();
		case 3:
			return currentFile.getCompressionSize();
		case 4:
			return currentFile.getOriginalSize();
		default:
			break;
		}
        return "";
	}
	private ArrayList<String> createDefaultTypeColums() {
		ArrayList<String> types = new ArrayList<String>();
		types.add("Name");
		types.add("Date");
		types.add("Time");
		types.add("Size Compressed");
		types.add("Real Size");
		return types;
	}
}
